package com.queue;

import java.util.concurrent.ConcurrentLinkedQueue;

public class TestQueue extends Thread{
	private QueueBean queueBean=null;
	private static Byte b= 1;
	private static ConcurrentLinkedQueue<QueueBean> queue=new ConcurrentLinkedQueue<QueueBean>();
	public TestQueue(QueueBean queueBean){
		this.queueBean=queueBean;
		queue.add(queueBean);
	}
	
	@Override
	public void run() {
		test();	
	}
	
	private void test(){
		synchronized (b) {			
		if(queue.isEmpty()){
			System.out.println("队列空了");
			return;
		}
		QueueBean q=queue.peek();
		System.out.println(this.hashCode()+"start");
		try {
			Thread.sleep(5*1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(this.hashCode()+"end");
		queue.poll();
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		for(int i=0;i<5;i++){
			QueueBean q=new QueueBean(""+Math.floor(Math.random()*100), "2", "2012", "05");
			TestQueue t=new TestQueue(q);
			t.start();
		}
	}

}
